﻿namespace CSharpPro;

public class Demo1
{
    public void Testprint1()
    {
        Console.WriteLine("请输入三个整数");
        string[] input = Console.ReadLine().Split();
        int x = int.Parse(input[0]);
        int y = int.Parse(input[1]);
        int z = int.Parse(input[2]);
        int[] sortedNumbers = SortThreeNumbers(x, y, z);
        Console.WriteLine("从小到大排列的结果为：");
        Console.WriteLine($"{sortedNumbers[0]} {sortedNumbers[1]} {sortedNumbers[2]}");
    }

    static int[] SortThreeNumbers(int a, int b, int c)
    {
        int temp;
        if (a > b)
        {
            temp = a;
            a = b;
            b = temp;
        }

        if (a > c)
        {
            temp = a;
            a = c;
            c = temp;
        }

        if (b > c)
        {
            temp = b;
            b = c;
            c = temp;
        }

        return new int[] { a, b, c };
    }

    public void Testprint2()
    {
        int sum = 0;
        Console.WriteLine("1-100中不含7且不是7的倍数的数有：");

        for (int i = 1; i <= 100; i++)
        {
            bool containsSeven = i.ToString().Contains("7");
            bool isMultipleOfSeven = i % 7 == 0;
            if (!containsSeven && !isMultipleOfSeven)
            {
                Console.Write(i + " ");
                sum += i;
            }
        }

        Console.WriteLine("\n\n这些数的总和是：" + sum);
    }

    public void Testprint3()
    {
        // 外层循环控制被乘数（1-9）
        for (int i = 1; i <= 9; i++)
        {
            // 内层循环控制乘数（1-当前被乘数）
            for (int j = 1; j <= i; j++)
            {
                // 格式化输出，保持对齐
                Console.Write($"{j}×{i}={i * j}\t");
            }

            // 每一行结束后换行
            Console.WriteLine();
        }
    }

    public void TestPrint4()
    {
        for (int i = 2; i <= 1000; i++)
        {
            int sum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    sum += j;
                }
            }

            if (sum == i)
            {
                Console.WriteLine(i + "");
            }
        }
    }

    public void TestPrint5()
    {
        int num;
        while (true)
        {
            Console.Write("请输入一个正整数：");
            if (int.TryParse(Console.ReadLine(), out num) && num > 0)
            {
                break;
            }

            Console.WriteLine("输入无效，请输入一个正整数！");
        }

        int temp = num;
        int digitCount = 0;
        while (temp > 0)
        {
            temp /= 10;
            digitCount++;
        }

        Console.WriteLine($"这个数字是{digitCount}位数");
        Console.Write("逆序打印各位数字：");
        temp = num;
        while (temp > 0)
        {
            int lastDigit = temp % 10;
            Console.Write(lastDigit + " ");
            temp /= 10;
        }

        Console.WriteLine();
    }

    public void TestPrint6()
    {
        int rows;
        while (true)
        {
            Console.Write("请输入菱形的行数（正整数）：");
            if (int.TryParse(Console.ReadLine(), out rows) && rows > 0)
            {
                break;
            }

            Console.WriteLine("输入无效，请输入一个正整数！");
        }

        PrintDiamond(rows);
    }

    static void PrintDiamond(int rows)
    {
        int upperRows = (rows + 1) / 2;
        for (int i = 1; i <= upperRows; i++)
        {
            for (int j = upperRows; j > i; j--)
            {
                Console.Write(" ");
            }

            for (int k = 1; k <= 2 * i - 1; k++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }

        int lowerRows = rows / 2;
        for (int i = lowerRows; i >= 1; i--)
        {
            for (int j = lowerRows; j >= i; j--)
            {
                Console.Write(" ");
            }

            for (int k = 1; k <= 2 * i - 1; k++)
            {
                Console.Write("*");
            }

            Console.WriteLine();
        }
    }
}
        
    




































































































































































































































































































































































































































































































































































    
   
   